package com.crm.system.controller.callCenter;

import com.crm.common.model.DataResponse;
import com.crm.common.model.DhPageInfo;
import com.crm.common.model.DhResponse;
import com.crm.common.model.Enum.ResponseCodeEnum;
import com.crm.model.qo.callCenter.CallFormQO;
import com.crm.model.qo.callCenter.CallMarkupQO;
import com.crm.model.vo.callCenter.CallFormDetailsVO;
import com.crm.model.vo.callCenter.CallFormVO;
import com.crm.system.service.callCenter.CallFormService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 呼叫中心-呼叫表单
 *
 * @Author renshaorong
 * @Date 2021/3/31
 */
@RestController
@RequestMapping("/callForm")
@Slf4j
public class CallFormController {

    @Autowired
    private CallFormService callFormService;

    /**
     * 呼叫表单列表
     *
     * @param pageIndex  页码
     * @param pageSize   分页大小
     * @param sortName   拍序列名字（暂时只支持创建时间排序）
     * @param sortOrder  排序规则(asc/desc)
     * @param callFormQO 查询条件
     * @return
     * @Author renshaorong
     * @Date 2021/4/1
     */
    @PostMapping("/selectCallFormList")
    public DataResponse selectClueList(@RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                       @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                       @RequestParam(value = "sortName", required = false) String sortName,//排序列名字
                                       @RequestParam(value = "sortOrder", required = false) String sortOrder,//排序规则(asc/desc)
                                       CallFormQO callFormQO//查询条件
    ) {
        DhPageInfo<CallFormVO> callFormVOList = callFormService.selectCallFormList(pageIndex, pageSize, callFormQO, sortName, sortOrder);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), callFormVOList);
    }

    /**
     * 根据联系人id获取详情信息
     *
     * @param contactId
     * @return
     */
    @GetMapping("/selectCallFormDetails")
    public DataResponse selectCallFormDetails(@RequestParam(value = "contactId") String contactId,
                                              @RequestParam(value = "formId") String formId) {
        CallFormDetailsVO details = callFormService.selectCallFormDetails(contactId, formId);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), details);
    }


    /**
     * 呼叫详情列表
     *
     * @param pageIndex  页码
     * @param pageSize   分页大小
     * @param sortName   拍序列名字（暂时只支持创建时间排序）
     * @param sortOrder  排序规则(asc/desc)
     * @param callFormQO 查询条件
     * @return
     * @Date 2021/4/9
     */
    @PostMapping("/selectCallDetailsList")
    public DataResponse selectCallDetailsList(@RequestParam(value = "pageIndex", required = false, defaultValue = "1") Integer pageIndex,//页码
                                              @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,//分页大小
                                              @RequestParam(value = "sortName", required = false) String sortName,//排序列名字
                                              @RequestParam(value = "sortOrder", required = false) String sortOrder,//排序规则(asc/desc)
                                              CallFormQO callFormQO//查询条件
    ) {
        DhPageInfo<CallFormVO> callFormVOList = callFormService.selectCallDetailsList(pageIndex, pageSize, callFormQO, sortName, sortOrder);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), callFormVOList);
    }


    /**
     * @Description: 修改呼叫表单的标签
     * @Author: yuanyunfeng
     * @Date: 2021/4/16 10:31
     * @Param: formId 表单id
     * @Param: label 标签
     * @Return:
     */
    @PostMapping("/updateLabel")
    public DataResponse updateLabel(@RequestParam(value = "formId") String formId, @RequestParam(value = "label") Integer label) {

        if (callFormService.updateLabel(formId, label)) {
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
        }
        return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
    }


    /**
     * @Description: 呼叫表单标记
     * @Param: [markupQO]
     * @Return: com.crm.common.model.DataResponse
     * @Author: lixq-f
     * @Date: 2021/5/28
     **/
    @PostMapping("/callMarkup")
    public DataResponse callMarkup(@RequestBody CallMarkupQO markupQO) {
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), callFormService.callMarkup(markupQO));
    }


    /**
     * @Description: 根据表单ID获取表单记录
     * @Param: [formId]
     * @Return: com.crm.model.entity.callCenter.CallForm
     * @Author: lixq-f
     * @Date: 2021/5/28
     **/
    @PostMapping("/selectCallFormByFormId")
    public DataResponse selectCallFormByFormId(@RequestParam(value = "formId") String formId) {
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), callFormService.selectCallFormByFormId(formId));
    }



    /**
     * @Description: 修改呼叫表单联系人名称
     * @Param: [callFormQO]
     * @Return: boolean
     * @Author: lixq-f
     * @Date: 2021/5/31
     **/
    @PostMapping("/updateContact")
    public DataResponse updateContact(@RequestBody CallFormQO callFormQO) {
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), callFormService.updateContact(callFormQO));
    }


}
